package megajournal.view;

import megajournal.controller.AdminCtrl;
import megajournal.view.ocDialog;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author cska
 * 
 */

public class GtsDlg extends JDialog implements ocDialog {

    protected GridBagConstraints c;
    protected JComboBox group, teacher, subject;
    protected AdminCtrl ctrl;
    protected JLabel l1, l2, l3;
    protected JPanel buttonPanel;
    protected JButton ok, cancel;

    public boolean fl;
    protected DefaultComboBoxModel groupModel, teacherModel, subjectModel;

    public GtsDlg(JFrame owner, boolean modal, String title, DefaultComboBoxModel groupModel,
            DefaultComboBoxModel teacherModel, DefaultComboBoxModel subjectModel,
            int groupIndex, int teacherIndex, int subjectIndex) {
        super(owner, title, modal);
        this.groupModel = groupModel;
        this.teacherModel = teacherModel;
        this.subjectModel = subjectModel;
        setLayout(new GridBagLayout());
        fl = false;

        c = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0);

        c.weightx = 0.1;
        l1 = new JLabel("Группа:", JLabel.RIGHT);
        add(l1,c);
        c.gridy = 1;
        l2 = new JLabel("Преподаватель:", JLabel.RIGHT);
        add(l2,c);
        c.gridy = 2;
        l3 = new JLabel("Предмет:", JLabel.RIGHT);
        add(l3,c);

        c.weightx = 0.9;
        c.gridx = 1;
        c.gridy = 0;
        group = new JComboBox(groupModel);
        group.setSelectedIndex(groupIndex);
        add(group,c);
        c.gridy = 1;
        teacher = new JComboBox(teacherModel);
        teacher.setSelectedIndex(teacherIndex);
        add(teacher,c);
        c.gridy = 2;
        subject = new JComboBox(subjectModel);
        subject.setSelectedIndex(subjectIndex);
        add(subject,c);

        c.gridx = 0;
        c.gridy = 0;
        c.fill = GridBagConstraints.CENTER;
        c.anchor = GridBagConstraints.EAST;
        c.weightx = 1.0;
        c.insets = new Insets(0, 0, 0, 5);
        buttonPanel = new JPanel(new GridBagLayout());
        ok = new JButton("Сохранить");
        ok.addActionListener(new okAdapter(this));
        buttonPanel.add(ok,c);
        c.gridx = 1;
        c.weightx = 0.0;
        c.insets = new Insets(0, 5, 0, 0);
        cancel = new JButton("Отмена");
        cancel.addActionListener(new cancelAdapter(this));
        buttonPanel.add(cancel,c);
        c.gridx = 0;
        c.gridy = 3;
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridwidth = 2;
        c.weightx = 1.0;
        c.insets = new Insets(5, 5, 5, 5);
        add(buttonPanel,c);

        setSize(480,180);
        Dimension screen = getToolkit().getScreenSize().getSize();
        setLocation((screen.width-480)/2, (screen.height-180)/2);
        setResizable(false);
        setDefaultCloseOperation(HIDE_ON_CLOSE);
        setVisible(true);
    }

    public int getGroup() {
        return group.getSelectedIndex();
    }

    public int getTeacher() {
        return teacher.getSelectedIndex();
    }

    public int getSubject() {
        return subject.getSelectedIndex();
    }

    public void ok() {
        fl = true;
        setVisible(false);
    }

    public void cancel() {
        fl = false;
        setVisible(false);
    }

}
